<?php
/**
 * +----------------------------------------------------------------------
 * | 九月科技-ztuc.cn
 * +----------------------------------------------------------------------
 *                      .::::.
 *                    .::::::::.            | AUTHOR: siyu
 *                    :::::::::::           | EMAIL: ztucke@ztuc.cn
 *                 ..:::::::::::'           | DATETIME: 2020/01/31
 *             '::::::::::::'
 *                .::::::::::
 *           '::::::::::::::..
 *                ..::::::::::::.
 *              ``::::::::::::::::
 *               ::::``:::::::::'        .:::.
 *              ::::'   ':::::'       .::::::::.
 *            .::::'      ::::     .:::::::'::::.
 *           .:::'       :::::  .:::::::::' ':::::.
 *          .::'        :::::.:::::::::'      ':::::.
 *         .::'         ::::::::::::::'         ``::::.
 *     ...:::           ::::::::::::'              ``::.
 *   ```` ':.          ':::::::::'                  ::::..
 *                      '.:::::'                    ':'````..
 * +----------------------------------------------------------------------
 */
/**
/**
 * Created by PhpStorm.
 * UserToken: Administrator
 * Date: 2020/3/14
 * Time: 17:18
 */
namespace app\lnadmin\controller;
use app\core\InitController;
use think\facade\View;
use app\lnadmin\model\admin\UserToken as UserTokenModel;

class UserToken extends InitController
{

    // 列表
    public function list()
    {
        return View::fetch('usertoken');
    }

   //列表详情 // 详情
    public function index_json($limit='15')
    {
        $UserToken = new UserTokenModel();
        $data = $UserToken->order('create_time asc')->paginate($limit);

         // 获取用户信息
        if (!empty($data)) {
            foreach ($data as $k => $v) {
                if ($v['token']){
                    $userInfo = \app\store\model\User::checkToken($v['token']);
                    $keep = \app\lnadmin\model\admin\Lnadmin::checkToken($v['token']);
                    $data[$k]['username'] = $userInfo['username']??$keep['username'];
                }
            }
        }
        $this->result($data);
    }
    
    // 删除
    public function del()
    { 
        if ($this->request->isPost()) { 
            $param = $this->request->param();
            $result = UserTokenModel::where(['user_id' => $param['user_id']])->delete(true);
            if ($result == true) {
                return $this->success('', '', '删除成功');
            }
        }
    }
}